﻿using Lan.ServiceCore.TargetCollection;

namespace Lan.ServiceCore.AlarmRecord
{
    public class AlarmRecord
    {

        public int Id { get; set; }
        public DateTime Time { set; get; }//报警时间
        public int AreaId { set; get; }//防区ID
        public string Name { set; get; }//防区名称

        public WDefenceArea DefenceArea { get; set; }
        public List<string> VideoName { set; get; }//算法使用视频，报警前2s
        public string WCameraIp { set; get; }//发送端相机ip
        //public string CameraNotUsedIp { set; get; }//接收端相机Ip
        public bool isCamera_General = false;
        public int AglResultSend { set; get; }//发送端相机算法执行结果
        public int AglResultRecv { set; get; }//接收端相机算法执行结果
        public bool IsBreakdown { set; get; }//是否故障报警（连续报警）
        //参数初始化
        public void Init()
        {
            try
            {
                Time = DateTime.Now;
                AreaId = -1;
                Name = "";
                WCameraIp = "";//发送端相机ip
                AglResultSend = -1;//发送端相机算法执行结果
                AglResultRecv = -1;//接收端端相机算法执行结果
                IsBreakdown = false;

                //TargetInfoList = new List<TargetInfo>();
            }
            catch (Exception ex)
            {
                //Log.Error(ex.ToString());
            }
        }

        public AlarmRecord()
        {
            Init();
        }

        //回放视频文件名前缀
        private string PathPrefix
        {
            get
            {

                //if (string.IsNullOrEmpty(TargetCommon.FilePath))
                //{
                //    SysConfigService sysConfigService = new SysConfigService();
                //    TargetCommon.FilePath = sysConfigService.GetSysConfigByKey("filepath").ConfigValue;
                //}

                string pt = "D:\video";

                string _strFlie = pt.Replace("\\", "/") + "/" + DateTime.Now.ToString("yyyy_MM_dd");
                EnsureDirExist(_strFlie);
                return _strFlie + "/" + DateTime.Now.ToString("yyyy.MM.dd_HH.mm.ss.ffff_");
            }
        }

        //确保目录存在
        public static void EnsureDirExist(string path)
        {
            try
            {
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);

                }
            }
            catch (Exception ex)
            {
                //Log.Error(ex.ToString());
            }
        }

        //生成视频文件名
        public string CreateVideoName(string ip)
        {
            try
            {
                string aa = "";
                aa = PathPrefix + ip + "video.mp4";
                return aa;
                //}
            }
            catch (Exception ex)
            {
                //Log.Error(ex.ToString());
                return "";
            }
        }



    }
}
